import Http from '@/api/http';
import SendMsgResponse from '@/modules/weChat/structure/sendMsgResponse';
import WxMaSubscribeMsgTemplate from '../structure/wxMaSubscribeMsgTemplate';
import WxMessageSendRequest from '../structure/wxMessageSendRequest';

const BASE_URL = 'wx/user/wx/ma/subscribeMsg';

/**
 * 微信小程序订阅消息
 */
class WxMaSubscribeMsgApi extends Http {
  /**
   * 获取模板列表
   * @param appId 应用ID
   * @return 模板列表
   */
  public getList(appId: string): Promise<WxMaSubscribeMsgTemplate[]> {
    return super.get0(`${BASE_URL}/${appId}/templateList`);
  }

  /**
   * 发送订阅消息
   * @param appId 应用ID
   * @param data 请求数据
   * @return 响应
   */
  public sendMsg(appId: string, data: WxMessageSendRequest): Promise<{ [key: string]: SendMsgResponse }> {
    return super.post0(`${BASE_URL}/${appId}/sendMsg`, data);
  }
}

export default new WxMaSubscribeMsgApi();
